﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>Create</title>
    <script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <link href='@Url.Content("~/Scripts/zTree/css/zTreeStyle/zTreeStyle.css")' rel="stylesheet" type="text/css" />
    <script src='@Url.Content("~/Scripts/zTree/js/jquery.ztree.core-3.5.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/Scripts/zTree/js/jquery.ztree.excheck-3.5.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/Scripts/zTree/js/jquery.ztree.exedit-3.5.js")' type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajaxSetup({ cache: false });
            $.getJSON("/TestPaper/GetAllChargeCourse", function (json) {
                for (var i = 0; i < json.length; i++) {
                    $("#sltCourses").append("<option value=\"" + json[i].ID + "\">" + json[i].Name + "</option>");
                }
            });
        })
        function GetAllStrategy(ctr) {
            var courseID = $(ctr).val();
            $.getJSON("/TestPaper/GetAllStrategyByCourseID", { id: courseID }, function (json) {
                var ids = json["tprIDs"];
                for (var i = 0; i < ids.length; i++) {
                    $("#divStrategy").append("<div style='float:left'><input id='chk" + i + "' type='checkbox' value='" + ids[i].id + "' /></div><div style='float:left'><ul id='tree" + i + "' class='ztree'></ul><div>");

                    var jsonTestPaper = json[ids[i].id];

                    var strategySetting = {};
                    var nodes = jsonTestPaper;
                    $.fn.zTree.init($("#tree" + i), strategySetting, nodes);
                }
            });
        };
        function SubmitPage() {
            var id;
            $("input:checkbox[checked='true']", "#divStrategy").each(function () {
                id = $(this).val();
            });
            $.post("/TestPaper/CreateTestPaperByRuleID", { id: id, name: function () { return $("#txtName").val() } }, function () {
                alert("提交成功！");
            });
        }
    </script>
</head>
<body>
    <p>
        @Html.ActionLink("返回列表", "Index")
    </p>
    <div>
        <div id="Title">
            <p>
                <span>请选择课程：</span>
                <select id="sltCourses" onchange="GetAllStrategy(this)">
                    <option>———请选择———</option>
                </select>
            </p>
            <p>
                <span>请输入试卷名称：</span><input id="txtName" type="text" />
            </p>
            <p>
                <span>请选择出题策略：</span>
                <div id="divStrategy" style=" width:100%; height:auto; float:left">
                </div>
            </p>
        </div>
    </div>
    <div>
         <input type="button" value="点击开始生成试卷数据" onclick="SubmitPage()" />
    </div>
</body>
</html>
